/**
 * @author yusak
 */
ChaShaKu.DraggableGrid = Ext.extend(Ext.app.Module,{
	id: 'draggableGrid',
	run: function(){
		this.app.modules.advancedSearchPanel.afterRenderedModules.push(this);
	},
	create: function(){
		var grid = this.app.modules.advancedSearchPanel.grid;
		var ds = grid.getStore();
		var sortOnDrop = function(dd, e, data){
			var sm = grid.getSelectionModel();
			var rows = sm.getSelections();
			var cindex = dd.getDragData(e).rowIndex;
			grid.stopEditing();
			if (!this.copy){
				for(i = 0; i < rows.length; i++) {
					ds.remove(ds.getById(rows[i].id));
				};
			};
			ds.insert(cindex,data.selections);
			sm.selectRow(cindex,false);
		}
		var ddrow = new Ext.dd.DropTarget(grid.getView().mainBody, {
			ddGroup: 'GridDD',
			copy: false,
			notifyDrop: sortOnDrop
		});
	}
});